package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.constant.MessageConstant;
import com.itheima.dao.MemberDao;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao memberDao;


    @Override
    public Member findTelephone(String telephone) {

        Member member = memberDao.findTelePhone(telephone);

        return member;
    }

    @Override
    public Result regest(Member member) {

        memberDao.add(member);
        return new Result(true, MessageConstant.LOGIN_SUCCESS);
    }

    @Override
    public List<Integer> findMemberCountByMonths(List<String> months) {

        List<Integer> memberCount = new ArrayList<>();

        for (String month : months) {
            month = month + ".31";

            Integer count = memberDao.findMemberCountByMonths(month);

            if (count == 0)
                throw new RuntimeException(MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);

            memberCount.add(count);

        }
        return memberCount;
    }



}
